﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Cource
{
    const int max_students = 30;

    private string name;
    private HashSet<Student> students;     

    public string Name
    {        
        get { return name; }
        set
        {
            if (name == null || name == "")
            {
                throw new ArgumentException(String.Format("Cource name cannot be empty!"));
            }
            else
            {
                name = value;
            }
        }
    }

    public HashSet<Student> Students
    {
        get { return students; }
    }

    public Cource()
    {
        this.name = string.Empty;
        this.students = new HashSet<Student>();
    }

    public Cource(string name, HashSet<Student> studentsList)
    {
        if (studentsList.Count > 30)
        {
            throw new StackOverflowException();
        }
        else
        {
            if (name == null || name == string.Empty)
            {
                throw new ArgumentException(String.Format("Cource name cannot be empty!"));
            }
            else
            {
                this.name = name;
                this.students = new HashSet<Student>();
                foreach (var item in studentsList)
                {
                    this.students.Add(item);
                }
            }
        }
    }

    public void JoinToCource(Student student)
    {
        if (this.students.Count == max_students)
        {
            throw new OverflowException(String.Format("Maximum number of students visiting this cource reached!"));
        }
        else
        {
            if (!this.students.Contains(student))
            {
                this.students.Add(student);
            }
            else
            {
                throw new Exception(String.Format("Student already visiting this cource!"));
            }
        }
    }

    public void LeaveCource(Student student)
    {
        if (student == null)
        {
            throw new ArgumentNullException();
        }
        else
        {
            if (!this.students.Contains(student))
            {
                throw new NullReferenceException("This student does not visit that cource!");
            }
            else
            {
                this.students.Remove(student);
            }
        }
    }
}

